<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>创建对象的方法</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        #app {

            margin: 0 auto;
            width: 80%;
            border: black 1px solid;
            height: 100vh;
        }
    </style>
</head>

<body>
    <div id="app"></div>
</body>
<script>
    //1.使用object创建
    let stu = new Object()
    //声明属性
    stu.name = 'tom'
    stu.id = 1
    stu.age = 20
    stu.gender = '男'
    //声明函数
    stu.toString = function () {
        return `{"id":"${this.id}","name":"${this.name}","age":"${this.age}","gender":"${this.gender}"}`
    }
    let info = stu.toString()
    app.innerHTML = info
</script>

</html>